<?php
$this->procSql(true);
$rs = $this->lastResult;

$rsT = $this->db->queryToArray("SELECT SUM(DEBE) AS SUMDEBE,SUM(HABER) AS SUMHABER FROM ($this->lastQuery) a");
$totales = count($rsT) > 0 ? $rsT[0] : array("SUMDEBE"=>0,"SUMHABER"=>0);

?>
<div class="dttb">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th scope="col">CUENTA</th>
            <th scope="col">FECHA</th>
            <th scope="col" width="40%" >DESCRIPCION</th>
            <th scope="col">DEBE</th>
            <th scope="col">HABER</th>
            <th scope="col">SALDO</th>
        </tr>
    </thead>
    <tbody>    
        <?php if (count($rs) > 0) {
            foreach ($rs as $r) { 
                $ks=  array_keys($r);
                ?>
                <tr>
                    <td><?php echo $r[$ks[0]] ?></td>
                    <td><?php echo date("d/m/Y",strtotime($r["FECHA"])) ?></td>
                    <td ><?php echo $r["DESCRIPCION"] ?></td>
                    <td><?php echo $r["DEBE"] ?></td>
                    <td><?php echo $r["HABER"]; ?></td>
                    <td><?php echo $r["SALDO"]; ?></td>                    
                </tr>
            <?php }
        } else { ?>
            <tr>
                <td colspan="5">No posee informacion!</td>
            </tr>  
        <?php } ?>
    </tbody>
    <tfoot>
        <tr>
            <th>&nbsp;</th>
            <th>&nbsp;</th>
            <th>&nbsp;</th>
            <th><?php echo $totales["SUMDEBE"]; ?></th>
            <th><?php echo $totales["SUMHABER"]; ?></th>
            <th>&nbsp;</th>
        </tr>
    </tfoot>
</table>
</div>